﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace MVVMLightDemo.Services
{
    public class ValidationRulesSet
    {
    }

    public class TelePhoneValidation : System.Windows.Controls.ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            string tel = value as string;
            bool isTel = Regex.IsMatch(tel, @"^\d{4}-?\d{7}|\d{3}-?\d{8}$");
            if (!isTel)
            {
                return new ValidationResult(false, "不是有效的电话号码balabalabalba！");
            }
            else
            {
                return new ValidationResult(true, null);
            }

        }
    }

    public class EmailValidation : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            string email = value as string;
            bool isEmail = Regex.IsMatch(email, @"[\w-]+(\.[\w-]+)?@[\w-]+(\.[\w-]+)+");
            if (isEmail)
            {
                return new ValidationResult(true, null);
            }
            else
            {
                return new ValidationResult(false, "不是有效的邮箱地址！");
            }
        }
    }

    public class NameValidation : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            string name = value as string;
            if (string.IsNullOrEmpty(name))
            {
                return new ValidationResult(false, "姓名不能为空！");
            }
            else
            {
                return new ValidationResult(true, null);
            }
        }
    }
}
